//
//  YiJianViewController.m
//  GuoBang
//
//  Created by fengshuai on 16/4/28.
//  Copyright © 2016年 梧桐树. All rights reserved.
//

#import "YiJianViewController.h"

@interface YiJianViewController ()<UITextViewDelegate, UITextFieldDelegate>

@end

@implementation YiJianViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupNVA];
    [self setupUI];
    [self setupData];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

}

- (void)setupNVA
{
    self.title=@"意见反馈";
    //设置返回按键
    //返回按键颜色
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    //返回按键图标
    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
}

- (void)leftAction:(UIBarButtonItem *)sender
{
     [self.navigationController popViewControllerAnimated:YES];
}

- (void)setupData
{
 
    
}

- (void)setupUI
{
    // 使用textView很关键的代码  光标在左上角
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor = RGBCOLOR(245, 245, 245);
    self.tiJiaoBtn.layer.cornerRadius = 5;
    self.tiJiaoBtn.layer.masksToBounds = YES;
    [self.tiJiaoBtn addTarget:self action:@selector(tijiaoAction:) forControlEvents:UIControlEventTouchUpInside];
    self.yiJianView.delegate = self;
    self.phoneTF.delegate = self;
 
    self.yiJianView.selectedRange=NSMakeRange(0,0) ;   //起始位置
    
    
}


- (void)tijiaoAction:(UIButton *)sender
{
    
    
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
    
}


-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    return YES;
    
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}


// 回车就结束编辑
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];

        return NO;
    }
    return YES;
}

// 当输入时让label消失
-(void)textViewDidBeginEditing:(UITextView *)textView
{
    self.placeholdLabel.hidden = YES;
}


-(void)textViewDidChange:(UITextView *)textView {
    CGRect line = [textView caretRectForPosition:
                   textView.selectedTextRange.start];
    CGFloat overflow = line.origin.y + line.size.height
    - ( textView.contentOffset.y + textView.bounds.size.height
       - textView.contentInset.bottom - textView.contentInset.top );
    if ( overflow > 0 ) {
        
        CGPoint offset = textView.contentOffset;
        offset.y += overflow + 7; // leave 7 pixels margin
        
        [UIView animateWithDuration:.2 animations:^{
            [textView setContentOffset:offset];
        }];
    }
}





@end
